package com.oneplatform.user.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesuite.common.util.AssertUtil;
import com.jeesuite.common.util.BeanUtils;
import com.jeesuite.mybatis.plugin.pagination.Page;
import com.jeesuite.springweb.model.WrapperResponse;
import com.jeesuite.security.client.LoginContext;
import com.oneplatform.base.model.IdParam;

import com.oneplatform.user.dto.param.UserAssetsQueryParam;
import com.oneplatform.user.dao.entity.UserAssetsEntity;
import com.oneplatform.user.dto.param.UserAssetsParam;
import com.oneplatform.user.service.UserAssetsService;

import io.swagger.annotations.ApiOperation;

/**
 * generated by www.jeesuite.com
 */
@Controller
@RequestMapping("/userAssets")
public class UserAssetsController {

    private @Autowired UserAssetsService userAssetsService;
	
	@ApiOperation(value = "分页查询")
	@RequestMapping(value = "list", method = RequestMethod.POST)
    public @ResponseBody Page<UserAssetsEntity> pageQueryUserAssetss(@RequestBody UserAssetsQueryParam param) {
		Page<UserAssetsEntity> page = userAssetsService.pageQuery(param,param);
		return page;
	}
	
	@ApiOperation(value = "按id查询")
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
    public @ResponseBody WrapperResponse<UserAssetsEntity> getById(@PathVariable("id") int id) {
		UserAssetsEntity entity = userAssetsService.findUserAssetsById(id);
		return new WrapperResponse<>(entity);
	}
	
	@ApiOperation(value = "新增")
	@RequestMapping(value = "add", method = RequestMethod.POST)
    public @ResponseBody WrapperResponse<String> addUserAssets(@RequestBody UserAssetsParam param) {
		UserAssetsEntity entity = BeanUtils.copy(param, UserAssetsEntity.class);
		//entity.setCreatedAt(new Date());
		//entity.setCreatedBy(LoginContext.getIntFormatUserId());
		userAssetsService.addUserAssets(entity);
		
		return new WrapperResponse<>();
	}
	
	@ApiOperation(value = "更新")
	@RequestMapping(value = "update", method = RequestMethod.POST)
    public @ResponseBody WrapperResponse<String> updateUserAssets(@RequestBody UserAssetsParam param) {
		UserAssetsEntity entity = BeanUtils.copy(param, UserAssetsEntity.class);
		//entity.setUpdatedAt(new Date());
		//entity.setUpdatedBy(LoginContext.getIntFormatUserId());
		userAssetsService.updateUserAssets(entity);
		
		return new WrapperResponse<>();
	}
	
	@ApiOperation(value = "删除")
	@RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
    public @ResponseBody WrapperResponse<String> deleteUserAssets(@RequestBody IdParam param) {
		userAssetsService.deleteUserAssets(param.getId());
		return new WrapperResponse<>();
	}
	
	
}
